package com.axon.mvc.patterns.command
{
	import com.axon.base.helpers.AxFailure;
	import com.axon.base.managers.AxErrorManager;
	import com.axon.mvc.helpers.AxMvcUtils;
	
	import flash.utils.getQualifiedClassName;
	
	import org.puremvc.as3.interfaces.ICommand;
	import org.puremvc.as3.interfaces.INotification;
	import org.puremvc.as3.patterns.command.SimpleCommand;

	public class AxSimpleCommand extends SimpleCommand implements ICommand
	{
		//////////////////////////////////////////////////////////////////////////////////////////////////////
		
		override public function execute(notification: INotification): void
		{
			var functionName: String =	AxMvcUtils.PREFIX_EXEC +
										AxMvcUtils.extractActionNameFromNotificationName(this, notification);
			
			var sender		: Object =  notification.getBody().hasOwnProperty(AxMvcUtils.TERM_SENDER) ?
										notification.getBody().sender :
										notification.getBody();
			
			var body		: Object =  notification.getBody().hasOwnProperty(AxMvcUtils.TERM_BODY) ?
										notification.getBody().body :
										notification.getBody();
			
			var extraInfo	: Object =	notification.getBody().hasOwnProperty(AxMvcUtils.TERM_EXTRA_INFO) ?
										notification.getBody().extraInfo :
										null;
			
			if (!this.hasOwnProperty(functionName)) {
				
				AxErrorManager.showFailure(new AxFailure(
					"Message for Software Engineers:\n\nHey guys, class " +
					getQualifiedClassName(this) + 
					" must implement method " + 
					functionName + 
					"(sender: Object, body: Object, extraInfo: Object) - Action execution handler.")); }
			else {
				
				this[functionName](sender, body, extraInfo);
			}
		}
		
	}
}